﻿<?php
defined("_VALID_ACCESS") || die('Direct access forbidden');
class SCTV_MaintenanceAcceptanceInstall extends ModuleInstall {
 
    public function install() { // Here you can place the installation process for the module
 
	Base_ThemeCommon::install_default_theme($this->get_type());
	
	$fields = array(
		array('name'=>_M('Maintenance'), 'type'=>'select', 'param'=>array('SCTV_Maintenance'=>'Maintenance Code'), 'required'=>true, 'visible'=>false),
		array('name'=>_M('Customer Name'), 'type'=>'text', 'param'=>128, 'required'=>false, 'visible'=>true),
		array('name'=>_M('Address'), 'type'=>'text', 'param'=>128, 'required'=>true, 'visible'=>true),
		array('name'=>_M('Receipt'), 'type'=>'text', 'param'=>32, 'required'=>true, 'visible'=>true),
		array('name'=>_M('Fee'), 'type'=>'text', 'param'=>32, 'required'=>true, 'visible'=>true, 'display_callback'=>array('SCTV_MaintenanceAcceptanceCommon', 'display_money')),
		array('name'=>_M('Deposit'), 'type'=>'text', 'param'=>32, 'required'=>true, 'visible'=>true, 'display_callback'=>array('SCTV_MaintenanceAcceptanceCommon', 'display_money')),
		array('name'=>_M('Note'), 'type'=>'text', 'param'=>256, 'required'=>false, 'visible'=>true),
		array('name'=>_M('Nhân viên quyết toán'), 'type'=>'calculated', 'extra'=>false, 'visible'=>true, 'required'=>false, 'display_callback'=>array('SCTV_MaintenanceAcceptanceCommon', 'display_nhan_vien_quyet_toan'), 'QFfield_callback'=>array('SCTV_MaintenanceAcceptanceCommon', 'QFfield_nhan_vien_quyet_toan')),
		array('name'=>_M('Checked'), 'type'=>'checkbox', 'extra'=>false, 'visible'=>true, 'required'=>true, 'display_callback'=>array('SCTV_MaintenanceAcceptanceCommon', 'display_checked'), 'QFfield_callback'=>array('SCTV_MaintenanceAcceptanceCommon', 'QFfield_checked'))
	);
	
	Utils_RecordBrowserCommon::install_new_recordset('SCTV_MaintenanceAcceptance', $fields);
	Utils_RecordBrowserCommon::set_caption('SCTV_MaintenanceAcceptance', _M('MaintenanceAcceptance'));
	Utils_RecordBrowserCommon::add_default_access('SCTV_MaintenanceAcceptance');
	
	$materialfields = array(
			array('name'=>_M('MaintenanceAcceptance'), 'type'=>'select', 'param'=>array('SCTV_MaintenanceAcceptance'=>'id'), 'required'=>true, 'visible'=>false),
			array('name'=>_M('Material'), 'type'=>'select', 'param'=>array('SCTV_Material'=>'Material Code|Material Name'), 'required'=>true, 'visible'=>true),
			array('name'=>_M('Material Type'), 'type'=>'integer', 'required'=>true, 'visible'=>true, 'display_callback'=>array('SCTV_MaintenanceAcceptanceCommon', 'display_material_type')),					
			array('name'=>_M('Amount'), 'type'=>'integer', 'required'=>true, 'visible'=>true),			
			array('name'=>_M('Price'), 'type'=>'integer', 'required'=>true, 'visible'=>true, 'display_callback'=>array('SCTV_MaintenanceAcceptanceCommon', 'display_money')),																				
			array('name'=>_M('Total'), 'type'=>'integer', 'param'=>32, 'required'=>true, 'visible'=>true, 'display_callback'=>array('SCTV_MaintenanceAcceptanceCommon', 'display_money'))			
		);
	
	Utils_RecordBrowserCommon::install_new_recordset('SCTV_MaintenanceAcceptanceMaterial', $materialfields);
	Utils_RecordBrowserCommon::set_caption('SCTV_MaintenanceAcceptanceMaterial', _M('Maintenance Acceptance Material'));
	Utils_RecordBrowserCommon::add_default_access('SCTV_MaintenanceAcceptanceMaterial');
	
	Utils_RecordBrowserCommon::new_addon('SCTV_Maintenance', 'SCTV_MaintenanceAcceptance', 'maintenance_acceptance_addon', _M('Fee').'-'._M('Material').'-'._M('Deposit'));
	Utils_RecordBrowserCommon::new_addon('SCTV_MaintenanceAcceptance', 'SCTV_MaintenanceAcceptance', 'material_addon', _M('Material'));
	
	$changerequestfields = array(
			array('name'=>_M('Maintenance'), 'type'=>'select', 'param'=>array('SCTV_Maintenance'=>'Maintenance Code'), 'required'=>true, 'visible'=>true),
			array('name'=>_M('Employee'), 'type'=>'crm_contact', 'param'=>array('field_type'=>'select', 'crits'=>array(), 'format'=>array('CRM_ContactsCommon','contact_format_default')), 'required'=>true, 'visible'=>true),
			array('name'=>_M('Status'), 'type'=>'integer', 'required'=>true, 'visible'=>true, 'extra'=>true, 'display_callback'=>array('SCTV_MaintenanceAcceptanceCommon', 'display_acceptance_request_status'), 'QFfield_callback'=>array('SCTV_MaintenanceAcceptanceCommon', 'QFfield_acceptance_request_status')),
			array('name'=>_M('Note'), 'type'=>'long text', 'required'=>false, 'visible'=>true),
			array('name'=>_M('Result'), 'type'=>'long text', 'required'=>false, 'visible'=>true)
		);
	Utils_RecordBrowserCommon::install_new_recordset('SCTV_MaintenanceAcceptanceChangeRequest', $changerequestfields);
	Utils_RecordBrowserCommon::set_caption('SCTV_MaintenanceAcceptanceChangeRequest', _M('Maintenance Acceptance ChangeReq'));
	Utils_RecordBrowserCommon::add_default_access('SCTV_MaintenanceAcceptanceChangeRequest');

    return true; // Return true on success and false on failure
    }
 
    public function uninstall() { // Here you can place uninstallation process for the module
		Base_ThemeCommon::uninstall_default_theme($this->get_type());
		Utils_RecordBrowserCommon::uninstall_recordset('SCTV_MaintenanceAcceptanceMaterial');
		Utils_RecordBrowserCommon::uninstall_recordset('SCTV_MaintenanceAcceptanceChangeRequest');
		Utils_RecordBrowserCommon::uninstall_recordset('SCTV_MaintenanceAcceptance');
				
		return true;
    }
 
    public function info() { // Returns basic information about the module which will be available in the epesi Main Setup
 
        return array( 'Author'=>'Tran Trong Hieu',
            'License'=>'SCTV',
                     'Description'=>'Maintenance Acceptance');
 
    }
 
    public function simple_setup() { // Indicates if this module should be visible on the module list in Main Setup's simple view
 
        return array('package' => __('Maintenance Acceptance'), 'version'=>'1.0'); // - now the module will be visible as "HelloWorld" in simple_view
 
    }
 
    public function requires($v) { // Returns list of modules and their versions, that are required to run this module
 
        return array();
 
    }
 
    public function version() { // Return version name of the module
 
        return array('1.0');
 
    }
}
 
?>